Skip to content

MkNode

:fa-brands-github: Show source on GitHub

Base class for everything which can be expressed as Markup.

Description

This class combines tree node functionality with markdown generation. Starting from the root nav (aka Docs) down to nested Markup blocks, the whole project can be represented by one tree.

MkNode is the base class for all nodes. We dont instanciate it directly. All subclasses carry an MkAnnotations node (except the MkAnnotations node itself) They can also pass an indent as well as a shift_header_levels keyword argument in order to modify the resulting markdown.

ancestors property

ancestors: Iterable[MkNode]

ctx property

ctx: ProjectContext

depth property

depth: int

descendants property

descendants: Iterable[MkNode]

env cached property

env

files property

files: dict[str, str | bytes]

is_leaf property

is_leaf: bool

is_root property

is_root: bool

left_sibling property

left_sibling: MkNode | None

max_depth property

max_depth: int

node_path property

node_path: list[MkNode]

parent property writable

parent: MkNode | None

parent_navs property

parent_navs: list[MkNav]

parent_page property

parent_page: MkPage | None

resolved_parts property

resolved_parts: tuple[str, ...]

right_sibling property

right_sibling: MkNode | None

root property

root: MkNode

siblings property

siblings: Iterable[MkNode]

__copy__

__copy__(**kwargs: Any) -> Self

__init__

__init__(
    *,
    header: str = "",
    indent: str = "",
    name: str | None = None,
    shift_header_levels: int = 0,
    variables: dict[str, Any] | None = None,
    context: ProjectContext | None = None,
    parent: MkNode | None = None,
    **_kwargs: Any
) -> None

Parameters:

Name Type Description Default
header str

Optional header for contained Markup

''
indent str

Indentation of given Markup (unused ATM)

''
name str | None

An optional unique identifier (allows getting node via MkNode.get_node)

None
shift_header_levels int

Regex-based header level shifting (adds/removes #-chars)

0
variables dict[str, Any] | None

Variables to use for rendering

None
context ProjectContext | None

Context this Nav is connected to.

None
parent MkNode | None

Parent for building the tree

None

add_css_class

add_css_class(class_name: str) -> None

Parameters:

Name Type Description Default
class_name str

CSS class to wrap the node with

required

add_file

add_file(filename: str, data: str | bytes) -> None

Parameters:

Name Type Description Default
filename str

Filename of the file to add

required
data str | bytes

Data of the file

required

attach_annotations

attach_annotations(text: str) -> str

Parameters:

Name Type Description Default
text str

Markdown to annote

required

attach_css_classes

attach_css_classes(text: str) -> str

Parameters:

Name Type Description Default
text str

Markdown to annote

required

get_children

get_children() -> list[MkNode]

get_content

get_content() -> NodeContent

get_input_requests

get_input_requests() -> list[InputRequest]

get_node classmethod

get_node(name: str) -> MkNode

get_node_resources

get_node_resources() -> Resources

get_nodefile classmethod

get_nodefile() -> NodeFile | None

get_processors

get_processors() -> list[TextProcessor]

get_resources

get_resources() -> Resources

get_toc

get_toc()

is_descendant_of

is_descendant_of(kls: type | UnionType) -> bool

Parameters:

Name Type Description Default
kls type | UnionType

The class (union) the check the ancestors for

required

iter_nodes

iter_nodes(indent: int = 0, max_depth: int | None = None) -> Iterator[tuple[int, MkNode]]

Parameters:

Name Type Description Default
indent int

The start "level". The first element of the returned tuple will be relative to this

0
max_depth int | None

The max depth to iterate

None

row

row() -> int

to_child_node

to_child_node(other: str | list[Any] | MkNode | None)

Parameters:

Name Type Description Default
other str | list[Any] | MkNode | None

The node / string to convert to a child node.

required

to_html

to_html(flavor: str | Renderer | None = None) -> str

Parameters:

Name Type Description Default
flavor str | Renderer | None

Markdown flavour (renderer name like "github" or a Renderer).

None

to_markdown

to_markdown(flavor: str | Renderer | None = None) -> str

Parameters:

Name Type Description Default
flavor str | Renderer | None

Markdown flavour (renderer name like "github" or a Renderer). Defaults to the active renderer (Material for MkDocs).

None

to_md_unprocessed

to_md_unprocessed() -> str

with_context classmethod

with_context(
    *args: Any, repo_url: str | None = None, base_url: str = "", **kwargs: Any
) -> Self
Name Children Inherits
MkContainerBase
mknodes.basenodes.mkcontainer
Abstract base class for nodes containing other MkNodes.
MkCompactAdmonition
mknodes.basenodes.mkcompactadmonition
Compact admonition info box.
    MkLink
    mknodes.basenodes.mklink
    A simple Link (with optional icon and option to show up as a button).
      MkText
      mknodes.basenodes.mktext
      Class for any Markup text.
      MkHeader
      mknodes.basenodes.mkheader
      Super simple header node.
        MkKeys
        mknodes.basenodes.mkkeys
        Node to display Keyboard keys.
          MkDocStrings
          mknodes.basenodes._mkdocstrings
          Docstring section (powered by mkdocstrings).
            MkIcon
            mknodes.basenodes.mkicon
            Pyconify-based Icon.
              MkImage
              mknodes.basenodes.mkimage
              Image including optional caption.
              MkProgressBar
              mknodes.basenodes.mkprogressbar
              Node to display a CSS-based progress bar.
                BaseBlock
                mknodes.pages.templateblocks
                A class representing a block from a page template.
                MkTimelineItem
                mknodes.basenodes.mktimeline
                Single Timeline item / card.
                  MkPyodideTerminal
                  mknodes.basenodes.mkpyodide
                  Node for embedding a Pyodide terminal running Python code.
                    MkJupyterLite
                    mknodes.basenodes.mkjupyterlite
                    Node for embedding a JupyterLite RetroLab interface.
                      MkPyScript
                      mknodes.basenodes.mkpyscript
                      Node for embedding a PyScript terminal.
                        MkDataClassInfo
                        mknodes.basenodes.mkdataclassinfo
                        Node for displaying dataclass-like object information.
                          MkNav
                          mknodes.navs.mknav
                          Nav section, representing a nestable menu.
                          MkTemplateTable
                          mknodes.templatenodes.mktemplatetable
                          Node for a table showing dependencies for a package.
                          MkPyDeps
                          mknodes.templatenodes.mkpydeps
                          Node for showing a Dependency graph.
                            FlavorComparison
                            mknodes.manual.flavors
                            Markdown of a node in the Material and the GitHub flavour, side by side.